import usePartState from "@module/usePartState";
import Filter from "@module/Filter";
import urlHook from "@page/common/utils/urlHook";


export default function TableComp(props) {
    const [stateObj, updateState] = usePartState({
        choosed:-1,
        choosedItem:{},

    });
    const {choosed,productSn}=stateObj;
    const lists=props.lists||[];

    function onClickRow(item,index) {
        updateState({
            choosed:index,
            choosedItem:item
        })
        props.onClick(item)
    }


    return(
        <div className={'bid-bidinput-table'}>
            <div className={'bid-bidinput-table-header'}>
                <span>商品编号</span>
                <span>商品名称</span>
                <span>品牌</span>
                <span id="bid-bidinput-table-header-price">价格</span>
            </div>
            <div style={{height:40}}/>
            <div className={'bid-bidinput-table-content'}>
                {
                    lists&&lists.map((item,index)=>{
                        const {name,code,price,brandName}=item;
                        return(
                            <div
                                onClick={()=>{
                                    onClickRow(item,index)
                                }}
                                key={index}
                                className={choosed==index? 'bid-bidinput-table-row bid-bidinput-row-choose':'bid-bidinput-table-row'}>
                                <span>{code}</span>
                                <span>{name}</span>
                                <span>{brandName||'无'}</span>
                                <span>{price&&Filter.float(price,2)}</span>
                            </div>
                        )
                    })
                }
            </div>

            {
                lists&&lists.length==0&&(
                    <div className={'bid-bidinput-modal-emity'}>
                        {
                            props.searchTxt?
                                <span>还没有此商品哦，请您点击</span>
                                :
                                <span>还没有商品哦，请您点击</span>
                        }

                        <span
                            onClick={()=>{
                                const proId=$state.params.id
                                window.open(urlHook.suppAddProduct(proId))
                            }}
                            className={'zen_0093EB zen_cur-p'}>新增商品</span>
                    </div>
                )
            }
            {lists&&lists.length>0&&lists.length<5&&
            (
                <div className={'zen-flex zen_m-t-40  zen_t-c'}>
                    <span>没有合适的竞价商品吗，请您点击</span>
                    <span
                        onClick={()=>{
                            const proId=$state.params.id
                            window.open(urlHook.suppAddProduct(proId))
                        }}
                        className={'zen_0093EB zen_cur-p'}>新增商品</span>
                </div>
            )
            }
            <div className="bid-bidinput-table-scrollend" id="r-bid-modal-table-end"></div>
        </div>
    )
}